#ifndef KENOCONN_H
#define KENOCONN_H

#include "connect.h"

class KenoGame;
class KenoBet;
class KenoPayout;
class KenoCard;

class KenoConnection : public Connection
{
	public:
		enum
		{
			MAX_SERVER_PICKS = 20,
			MAX_PICK = 80
		};
		typedef struct 
		{
			uint8	m_picks[MAX_SERVER_PICKS];
			int32	m_payout;
		}GAMERESULT;


		KenoConnection(Server*server, SOCKET client);
		~KenoConnection();

		void msgStart();
		void msgAdd(uint8 Byte);
		void msgAdd(int32 SignedLong);
		uint8* msgGetBuf();
		void msgReleaseBuf(int32 Amt);
		void msgEnd();

		KenoPayout *GetPayTable() { return m_paytable; }

		uint8	trackGetPayTable();
		bool8	trackGetBalance(int32 *);
		int32	trackAdjustBalance(int32);	// + increases  - decreases
		bool8	trackGetPlayerLimits(int32* compFactor);
		bool8	trackNewGame(KenoBet *bet, int32 *Balance, int32 numGames, bool8 newGroup);
		bool8	trackGameDone(int32 BalAdjust, int32* Balance, int32 *results);
		void	trackaddBadPacket(int32 error_reason, char MessageType, char *msgbuf, int32 msglen);

	protected:
		bool8	getResponse();

		void	sendStopMsg();

		bool8	parseAnsiCasinoLogin(int32*);
		bool8	parseUnicodeCasinoLogin(int32*);
		void	removeCasinoSpecific();

		void    HandleANSILogin(int32 nMsgLen);
		void	HandleUnicodeLogin(int32 nMsgLen);
		void    HandleLogin(int32 nMsgLen);
		void	HandleBet(int32 nMsgLen);
		void	HandleUnknownMessage(int32 nMsgLen);

		int32	encode(uint8*, uint8*, int32);
		int32	decode(uint8*, uint8*, int32);

		int32	msgRemove(uint8*, int32*);
		bool8 playGame (KenoCard& card, int32 numgames, bool8 newGroup, GAMERESULT& gresult, int32& balance);
		void ProcessBet (uint8* buf, int32 len, int32 num_cards, int32 num_games);
		void addCardToBuf (int32* picks, int32 numpicks, int32 payout);



	public:
		void	gameDone();

	protected:
		int32 		loggedOn;
		KenoGame	*m_game;
		void* 		casinoSpecific;
		int32 		minBet, maxBet;
		int32		cardCost;
		int32		m_paytables[14][14];
		int32 		compFactor;
		int32 		msglen;
		uint8 		msgbuf[OUTMAX];
		KenoPayout	*m_paytable;
};

#endif
